package org.geektimes.interceptor.jdkproxy;

import static java.lang.String.format;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * jdk proxy interceptor.
 * <br> @author leo
 * <br> @date 2021/7/27
 * <br> @since 1.0.0
 */
public class EchoJdkProxyImpl implements EchoJdkProxy {

    @Override
    public void bulkhead() {
        System.out.println(format("[%s] - pool",
                Thread.currentThread().getName()));
    }

    @Override
    public void echo(String message) {
        System.out.println(format("[%s] - echo : %s",
                Thread.currentThread().getName(), message));
        try {
            TimeUnit.MILLISECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Future<Void> echo(Object message) {
        System.out.println(format("[%s] - echo : %s",
                Thread.currentThread().getName(), message));
        return null;
    }

    @Override
    public String echo(Long value) {
        throw new UnsupportedOperationException("unsupported operation exception !");
    }

    @Override
    public String fallback(Long value) {
        return format("fallback result: %d",value);
    }
}
